import commonjs from '@rollup/plugin-commonjs'
import resolve from '@rollup/plugin-node-resolve'
import babel from '@rollup/plugin-babel'
import copy from 'rollup-plugin-copy'
import serve from 'rollup-plugin-serve'

const path = require('path')

const extensions = ['.js', '.jsx', '.ts', '.tsx']

// Base Plugins
const plugins = [
  // Allows node_modules resolution
  resolve({ extensions }),
  // Allow bundling cjs modules. Rollup doesn't understand cjs
  commonjs(),
  // Compile TypeScript/JavaScript files
  babel({
    extensions,
    exclude: "node_modules/**", // 只编译我们的源码
    // runtimeHelpers: true,
  }),
  copy({
    targets: [
      {src: 'src/example/index.html', dest: 'docs'}
    ]
  }),
  serve({
    contentBase: 'docs'
  }),
]

const appConfig = {
  // input: "../src/example/app.ts",
  input: path.resolve(__dirname, '../src/example/app.ts'),
  plugins,
  output: {
    file: 'docs/app.js',
    format: 'es'
  }
}

export default [appConfig]